﻿<local:ResizableRectangle 
    x:Class="ImageCropper.CropRectangle"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:local="clr-namespace:ImageCropper"
    IsTabStop="True"   
    KeyDown="UserControl_KeyDown"
    GotFocus="UserControl_GotFocus"
    LostFocus="UserControl_LostFocus"    
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <vsm:VisualStateManager.VisualStateGroups>
            <vsm:VisualStateGroup x:Name="CommonStates">
                <vsm:VisualState x:Name="Normal"/>
                <vsm:VisualState x:Name="MouseOver"/>
                <vsm:VisualState x:Name="Pressed"/>
                <vsm:VisualState x:Name="Disabled"/>
            </vsm:VisualStateGroup>
            <vsm:VisualStateGroup x:Name="FocusStates">
                <vsm:VisualState x:Name="Focused">
                    <Storyboard>
                        <DoubleAnimation From="1" To="2" 
                                         Duration="0:0:0.25"
                                         Storyboard.TargetName="_border" 
                                         Storyboard.TargetProperty="StrokeThickness"/>
                        <DoubleAnimation From="20" To="0"
                                         BeginTime="0:0:0.25"
                                         Duration="0:0:1"
                                         Storyboard.TargetName="_border" 
                                         Storyboard.TargetProperty="StrokeDashOffset" 
                                         RepeatBehavior="Forever"/>
                    </Storyboard>                    
                </vsm:VisualState>
                <vsm:VisualState x:Name="Unfocused"/>
            </vsm:VisualStateGroup>
        </vsm:VisualStateManager.VisualStateGroups>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="6"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="6"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="6"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="6"/>
        </Grid.RowDefinitions>


        <Rectangle Margin="0" StrokeThickness="4" Stroke="#CCFFFFFF" Grid.ColumnSpan="3" Grid.RowSpan="3"/>
        <Rectangle x:Name="_border" Margin="0" StrokeThickness="1" Stroke="Black" StrokeDashArray="5,5" Grid.ColumnSpan="3" Grid.RowSpan="3"/>

        <Rectangle
            x:Name="_center"
            MouseMove="_center_MouseMove"
            Cursor="Hand" Fill="Transparent" Grid.Row="1" Grid.Column="1"/>

        <Rectangle 
            x:Name="_northWestEdge"
            MouseMove="_northWestEdge_MouseMove"
            Cursor="SizeNWSE" Fill="Transparent" Grid.Row="0" Grid.Column="0"/>
        <Rectangle 
            x:Name="_northEdge"             
            MouseMove="_northEdge_MouseMove"
            Cursor="SizeNS" Fill="Transparent" Grid.Row="0" Grid.Column="1"/>
        <Rectangle 
            x:Name="_northEastEdge" 
            MouseMove="_northEastEdge_MouseMove"
            Cursor="SizeNESW" Fill="Transparent" Grid.Row="0" Grid.Column="2"/>

        <Rectangle 
            x:Name="_westEdge" 
            MouseMove="_westEdge_MouseMove"
            Cursor="SizeWE" Fill="Transparent" Grid.Row="1" Grid.Column="0"/>
        <Rectangle 
            x:Name="_eastEdge"             
            MouseMove="_eastEdge_MouseMove"
            Cursor="SizeWE" Fill="Transparent" Grid.Row="1" Grid.Column="2"/>

        <Rectangle 
            x:Name="_southWestEdge"
            MouseMove="_southWestEdge_MouseMove"
            Cursor="SizeNESW" Fill="Transparent" Grid.Row="2" Grid.Column="0"/>
        <Rectangle 
            x:Name="_southEdge"            
            MouseMove="_southEdge_MouseMove"
            Cursor="SizeNS" Fill="Transparent" Grid.Row="2" Grid.Column="1"/>
        <Rectangle 
            x:Name="_southEastEdge" 
            MouseMove="_southEastEdge_MouseMove"
            Cursor="SizeNWSE" Fill="Transparent" Grid.Row="2" Grid.Column="2"/>
    </Grid>
</local:ResizableRectangle>
